//
//  ZZAudioModel.m
//  RecorderTest
//
//  Created by 张彦东 on 2017/5/18.
//  Copyright © 2017年 Z. All rights reserved.
//

#import "ZZAudioModel.h"

@implementation ZZAudioModel

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_name forKey:@"name"];
    [aCoder encodeObject:_url forKey:@"url"];
    [aCoder encodeObject:_duration forKey:@"duration"];
    [aCoder encodeObject:_fileSize forKey:@"filesize"];
    [aCoder encodeObject:_audioId forKey:@"audioId"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        _name = [aDecoder decodeObjectForKey:@"name"];
        _url = [aDecoder decodeObjectForKey:@"url"];
        _duration = [aDecoder decodeObjectForKey:@"duration"];
        _fileSize = [aDecoder decodeObjectForKey:@"filesize"];
        _audioId = [aDecoder decodeObjectForKey:@"audioId"];
        [self setupDisp];
    }
    return self;
}

- (void)setDuration:(NSNumber *)duration {
    _duration = duration;
    [self setupDisp];
}
- (void)setFileSize:(NSNumber *)fileSize {
    _fileSize = fileSize;
    [self setupDisp];
}

- (void)setupDisp {
    if (_duration) _durationDisp = [NSString stringWithFormat:@"时长: %.02f秒", _duration.floatValue];
    if (_fileSize) _fileSizeDisp = [NSString stringWithFormat:@"大小: %.02fMB", _fileSize.floatValue / 1024.00f / 1024.00f];
}

- (NSString *)description {
    return [NSString stringWithFormat:@"id:%@, name:%@, size:%@, duration:%@, url:%@", _audioId.stringValue, _name, _fileSize.stringValue, _duration.stringValue, _url.absoluteString];
}

@end
